﻿#define _CRT_SECURE_NO_WARNINGS 1
#include "Tree.h"

BTNode* buyNode(BTDataType x)
{
	BTNode* newnode = (BTNode*)malloc(sizeof(BTNode));
	if (newnode==NULL)
	{
		perror("malloc error!");
		exit(1);
	}
	newnode->data = x;
	newnode->left = newnode->right = NULL;
	return newnode;
}

void test01()
{
	BTNode* node1 = buyNode(1);
	BTNode* node2 = buyNode(2);
	BTNode* node3 = buyNode(3);
	BTNode* node4 = buyNode(4);
	BTNode* node5 = buyNode(5);

	node1->left = node2;
	node1->right = node3;
	node2->left = node4;
	//node4->left = node5;

	PreOrder(node1);
	printf("\n");
	InOrder(node1);
	printf("\n");
	PostOrder(node1);
	printf("\n");
	printf("二叉树结点个数:%d\n", BinaryTreeSize(node1));
	printf("二叉树叶子结点个数:%d\n", BinaryTreeLeafSize(node1));
	printf("二叉树第k层结点个数:%d\n", BinaryTreeLevelKSize(node1,3));
	printf("二叉树的深度/高度:%d\n", BinaryTreeDepth(node1));
	BTNode* find = BinaryTreeFind(node1, 3);
	printf("%s\n", find == NULL ? "没找到！" : "找到了！");
	BinaryTreeDestory(&node1);

}


int main()
{
	test01();
	return 0;
}